<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.BackOfficeModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%=ViewData["PageTitle"]%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <link href="/Content/start/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .original
        {
            width: 755px;
            height: 200px;
            overflow:auto;
        }
        .preview
        {
            width: 755px;
            height: 200px;
            overflow:auto;
        }
        .editemail-ta
        {
            height: 10em;
            width: 490px;
        }
        .editcontainer
        {
            border:medium double #87AAE1;
        }
        .style1
        {
            font-size: x-small;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="contentpage-outerdiv">
        <span class="field-validation-error">&nbsp;
            <%=ViewData["message"].ToString()%></span>
        <h1>
            <%=ViewData["PageTitle"]%></h1>
        <div>
            <div id="editEmailContentCommentReply">
                Comment Reply Email Template - <a href="javascript:void(0);" onclick="EditTemplate('CommentReply', true)">
                    Edit Comment Reply Template</a> <span class="style1">(&lt;&lt;pagename&gt;&gt;, &lt;&lt;sitename&gt;&gt;, &lt;&lt;user.name&gt;&gt;, &lt;&lt;reply.body&gt;&gt;, &lt;&lt;url&gt;&gt;)</span>
            </div>
            <div class="editcontainer">
                <div id="originalEmailContentCommentReply" class="original">
                    <%= ViewData["CommentReply"]%>
                </div>
                <div id="previewEmailContentCommentReply" class="preview" style="display: none;">
                </div>
            </div>
        </div>
        <div>
            <div id="editEmailContentResetPassword">
                Reset Password Email Template - <a href="javascript:void(0);" onclick="EditTemplate('ResetPassword', true)">
                    Edit Reset Password Template</a>
                <span class="style1">(&lt;&lt;sitename&gt;&gt;, &lt;&lt;user.newpassword&gt;&gt;, &lt;&lt;url&gt;&gt;)
                </span>
            </div>
            <div class="editcontainer">
                <div id="originalEmailContentResetPassword" class="original">
                    <%= ViewData["ResetPassword"]%>
                </div>
                <div id="previewEmailContentResetPassword" class="preview" style="display: none;">
                </div>
            </div>
        </div>
        <div>
            <div id="editEmailContentConfirmation">
                Confirmation Email Template - <a href="javascript:void(0);" onclick="EditTemplate('Confirmation', true)">
                    Edit Confirmation Template</a> (&lt;&lt;confirmationnumber&gt;&gt;, &lt;&lt;datetime.now&gt;&gt;, &lt;&lt;total&gt;&gt;, &lt;&lt;portalname&gt;&gt;, &lt;&lt;payername&gt;&gt;, &lt;&lt;comment&gt;&gt;, &lt;&lt;cardtpe&gt;&gt;, &lt;&lt;invoicenumber&gt;&gt;, &lt;&lt;businessname&gt;&gt;, &lt;&lt;dynamicfield&gt;&gt;, &lt;&lt;subscriptionname&gt;&gt;, &lt;&lt;portal.adminemail&gt;&gt;, &lt;&lt;portal.phone&gt;&gt;)
            </div>
            <div class="editcontainer">
                <div id="originalEmailContentConfirmation" class="original">
                    <%= ViewData["Confirmation"]%>
                </div>
                <div id="previewEmailContentConfirmation" class="preview" style="display: none;">
                </div>
            </div>
        </div>        
        <div>
            <div id="editEmailContentWelcome">
                Welcome Email Template - <a href="javascript:void(0);" onclick="EditTemplate('Welcome', true)">
                    Edit Welcome Template</a> <span class="style1">(&lt;&lt;user.username&gt;&gt;, &lt;&lt;url&gt;&gt;)
                </span>
            </div>
            <div class="editcontainer">
                <div id="originalEmailContentWelcome" class="original">
                    <%= ViewData["Welcome"]%>
                </div>
                <div id="previewEmailContentWelcome" class="preview" style="display: none;">
                </div>
            </div>
        </div>                
    </div>
    <div id="editEmailForm">
        <form action="/backoffice/EditEmailTemplate" method="post">
        <fieldset>
            <label for="Source">
                Source:</label>
            <%= Html.TextArea("Source", new { @class = "editemail-ta" })%>
            <%= Html.Hidden("EditedEmailID") %>
            <input type="submit" value="Save" />
            <input id="cancelEdit" type="button" value="Cancel" />
        </fieldset>        
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="SidebarContent" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ScriptContent" runat="server">

    <script src="/Scripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        var currentEmailId;
        var original, preview, cnt;

        cnt = $('#editEmailContentCommentReply');
        original = $('#originalEmailContent');
        preview = $('#previewEmailContent');

        function EditTemplate(emailid) {
            var dlg = $('#editEmailForm');

            cnt = $('#editEmailContent' + emailid);
            original = $('#originalEmailContent' + emailid);
            preview = $('#previewEmailContent' + emailid);

            currentEmailId = emailid;
            $('#EditedEmailID').val(emailid);
            if (!dlg.dialog('isOpen')) {
                $.post('/backofficeajax/gettemplatesource/' + emailid, function(data) {
                    $('#Source').val(data);
                    original.hide();
                    preview.html(original.html()).show();
                    dlg.dialog('open');
                });
            } else {
                dlg.dialog('close');
            }
        }

        var timeout = null;
        $(function() {

            var dlg = $('#editEmailForm');
            var cntPos = cnt.position();
            dlg.dialog({ autoOpen: false,
                width: 550,
                position: [cntPos.left - 300 + cnt.outerWidth(), cntPos.top + cnt.outerHeight() - 3000],
                show: 'blind',
                hide: 'blind',
                resizable: true,
                beforeclose: function() { original.show(); preview.hide(); }
            });

            $('#Source').keyup(function(e) {
                if (timeout != null) {
                    clearTimeout(timeout);
                    timeout = null;
                }

                var self = $(this);
                timeout = setTimeout(function() {
                    $.post('/backofficeajax/templatepreview/' + currentEmailId,
                           { source: self.val() },
                           function(data) { preview.html(data); });
                }, 250);
            });

            $('#cancelEdit').click(function() {
                dlg.dialog('close');
            });
        });        
    
    

    </script>

</asp:Content>
